package xupt.com.bolg.config.intercepors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import xupt.com.bolg.entity.User;
import xupt.com.bolg.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class ManagerHandleIntercepors implements HandlerInterceptor {
    @Autowired
    UserServiceImpl userService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String  name =(String) request.getSession().getAttribute("name");
        User byName = userService.findByName(name);
        if(byName.getManager()==1){
            return true;
        }
        response.sendRedirect("/home");
        return false;
    }
}
